package org.rohmh.comment.service;

import java.util.List;

import org.rohmh.question.domain.Question;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreFilter;
import org.springframework.transaction.annotation.Transactional;

@PreAuthorize("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')")
public interface CommentService {

    @PostFilter("filterObject.email == principal.username or hasRole('ROLE_ADMIN')")
    List<Question> findAll();

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    List<Question> findByLastName(String lastName);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @Transactional
    void persist(Question entity);

    @PreFilter("filterObject.email == principal.username")
    @Transactional
    void merge(Question entity);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @Transactional
    void remove(Question entity);

    Question find(Long id);
}
